package com.myjob.system.controller;

import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shopgoods.common.core.domain.R;
import com.shopgoods.common.core.utils.StringUtils;
import com.shopgoods.common.core.utils.file.FileTypeUtils;
import com.shopgoods.common.core.utils.file.MimeTypeUtils;
import com.shopgoods.common.security.utils.SecurityUtils;
import com.shopgoods.system.api.RemoteFileService;
import com.shopgoods.system.api.domain.SysFile;
import com.shopgoods.system.api.domain.SysRole;
import com.shopgoods.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.shopgoods.common.log.annotation.Log;
import com.shopgoods.common.log.enums.BusinessType;
import com.shopgoods.common.security.annotation.RequiresPermissions;
import com.myjob.system.domain.SgType;
import com.myjob.system.service.ISgTypeService;
import com.shopgoods.common.core.web.controller.BaseController;
import com.shopgoods.common.core.web.domain.AjaxResult;
import com.shopgoods.common.core.utils.poi.ExcelUtil;
import com.shopgoods.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 品牌Controller
 *
 * @author shopgoods
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/type")
public class SgTypeController extends BaseController
{
    @Autowired
    private ISgTypeService sgTypeService;



    /**
     * 查询品牌列表
     */
    @RequiresPermissions("system:type:list")
    @GetMapping("/list")
    public TableDataInfo list(SgType sgType)
    {
        startPage();
        List<SgType> list = sgTypeService.selectSgTypeList(sgType);
        return getDataTable(list);
    }

    /**
     * 导出品牌列表
     */
    @RequiresPermissions("system:type:export")
    @Log(title = "品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SgType sgType)
    {
        List<SgType> list = sgTypeService.selectSgTypeList(sgType);
        ExcelUtil<SgType> util = new ExcelUtil<SgType>(SgType.class);
        util.exportExcel(response, list, "品牌数据");
    }

    /**
     * 获取品牌详细信息
     */
    @RequiresPermissions("system:type:query")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(sgTypeService.selectSgTypeByTypeId(typeId));
    }

    /**
     * 新增品牌
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated SgType sgType)
    {
        return toAjax(sgTypeService.insertSgType(sgType));
    }

    /**
     * 修改品牌
     */
    @RequiresPermissions("system:type:edit")
    @Log(title = "品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SgType sgType)
    {
        return toAjax(sgTypeService.updateSgType(sgType));
    }

    /**
     * 删除品牌
     */
    @RequiresPermissions("system:type:remove")
    @Log(title = "品牌", businessType = BusinessType.DELETE)
    @DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(sgTypeService.deleteSgTypeByTypeIds(typeIds));
    }


    /**
     * 图片上传
     */
    @PostMapping("/avatar")
    public R<SysFile> avatar(MultipartFile file) {
        return sgTypeService.avatar(file);
    }


    /**
     * 修改品牌是否启用
     */
    @PutMapping("/updateTypeDisplayData")
    public AjaxResult updateTypeDisplayData(@RequestBody SgType sgType)
    {
        return toAjax(sgTypeService.updateSgTypeDisplay(sgType));
    }


    /**
     * 修改品牌制造商是否启用
     */
    @PutMapping("/updateTypeMakerData")
    public AjaxResult updateTypeMakerData(@RequestBody SgType sgType)
    {
        return toAjax(sgTypeService.updateTypeMakerData(sgType));
    }




}
